//
//  VisitorView.swift
//  DSWeibo
//
//  Created by liuzhu on 2018/10/30.
//  Copyright © 2018 liuzhu. All rights reserved.
//

import UIKit
protocol VisitorViewDelegate:NSObjectProtocol{
    func loginBtnWillClick()
    func registerBtnWillClick()
}
class VisitorView: UIView {
    
    weak var delegate:VisitorViewDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(iconView)
        addSubview(homeIcon)
        addSubview(messageLable)
        addSubview(loginButton)
        addSubview(registerButton)
        iconView.xmg_AlignInner(type: XMG_AlignType.Center, referView: self, size: nil)
        homeIcon.xmg_AlignInner(type: XMG_AlignType.Center, referView: self, size: nil)
        messageLable.xmg_AlignInner(type: XMG_AlignType.BottomCenter, referView: iconView, size: nil, offset: CGPoint(x: 0, y: 10))
        //哪个控件的什么属性 等于另外一个控件的 什么属性 乘以多少 加上多少
        let messageCons = NSLayoutConstraint.init(item: messageLable, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1.0, constant: 224)
        addConstraint(messageCons)
        registerButton.xmg_AlignInner(type: XMG_AlignType.BottomLeft, referView: messageLable, size: CGSize(width: 100, height: 30), offset: CGPoint(x: 0, y: 60))
        loginButton.xmg_AlignInner(type: XMG_AlignType.BottomRight, referView: messageLable, size: CGSize(width: 100, height: 30), offset: CGPoint(x: 0, y: 60))
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("")
    }
    
    private lazy var iconView :UIImageView = {
        let iv = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
        return iv
    }()
    
    private lazy var homeIcon :UIImageView = {
        let iv = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        return iv
    }()
    
    private lazy var messageLable :UILabel = {
        let label =  UILabel()
        label.text = "afewfasfew"
        label.numberOfLines = 0
        label.textColor = UIColor.darkGray
        label.textAlignment = NSTextAlignment.center
        return label
    }()
    
    private lazy var loginButton :UIButton = {
        let btn = UIButton()
        btn.setTitle("登录", for: UIControl.State.normal)
        btn.setTitleColor(UIColor.lightGray, for: UIControl.State.normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), for: UIControl.State.normal)
        btn.addTarget(self, action: #selector(loginBtnClick), for: UIControl.Event.touchUpInside)
        return btn
    }()
    
    private lazy var registerButton :UIButton = {
        let btn = UIButton()
        btn.setTitle("注册", for: UIControl.State.normal)
         btn.setTitleColor(UIColor.lightGray, for: UIControl.State.normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), for: UIControl.State.normal)
        btn.addTarget(self, action:  #selector(registerBtnClick), for: UIControl.Event.touchUpInside)
        return btn
    }()
    
    @objc private func loginBtnClick(){
        delegate?.loginBtnWillClick()
    }
    
    @objc private func registerBtnClick(){
        delegate?.registerBtnWillClick()
    }
    
    
}
